package com.hq.controller;


import com.hq.model.Guide;
import com.hq.model.Passenger;
import com.hq.model.Root;
import com.hq.service.GuideService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * 导游
 */
@Controller
@RequestMapping("/back/guide")
public class GuideController {

    @Resource
    private GuideService guideService;

    //显示导游信息
    @RequestMapping("/list")
    String allGuide(Model model, HttpSession session) {
        Root root = (Root) session.getAttribute("root");
        String username = root.getUsername();
        Guide list = guideService.selectMe(username);
        System.out.println(list);
        model.addAttribute("selectMe", list);
        return "/back/guide/list";
    }

    //修改
    @RequestMapping("/updateGuide")
    public String updateMe(Model model, HttpSession session) {
        Root root = (Root) session.getAttribute("root");
        String username = root.getUsername();
        Guide guide = guideService.selectMe(username);
        model.addAttribute("Guide", guide);
        return "/back/guide/updateGuide";
    }

    @RequestMapping("/updataInfo")
    String updataInfo(Guide guide){
        guideService.updateMe(guide);
        return "redirect:/back/guide/list";
    }

    //查看游客
    @RequestMapping("/allPassenger")
    String selectMyPassenger(Model model, HttpSession session){
        Root root = (Root) session.getAttribute("root");
        String username = root.getUsername();
        Guide list = guideService.selectMe(username);
        String name = list.getName();
        List<Passenger> passengerList = guideService.findPassenger(name);
        System.out.println(passengerList.toString());
        model.addAttribute("PassengerList",passengerList);
        return "/back/guide/allPassenger";
    }

}
